<template>
  <el-drawer direction="rtl" :visible="openView" :before-close="onCloseView" :show-close="false" size="500px" :with-header="false">
    <!-- 任务详细 -->
    <el-descriptions title="任务详细" direction="vertical" :column="2" border class="descriptions-container">
      <el-descriptions-item label="任务编号" :span="2">{{ scheduleJob.id }}</el-descriptions-item>
      <el-descriptions-item label="任务名称">{{ scheduleJob.jobName }}</el-descriptions-item>
      <el-descriptions-item label="任务分组">{{ scheduleJob.jobGroup }}</el-descriptions-item>
      <el-descriptions-item label="调用目标" :span="2">{{ scheduleJob.invokeTarget }}</el-descriptions-item>
      <el-descriptions-item label="cron表达式">{{ scheduleJob.cron }}</el-descriptions-item>
      <el-descriptions-item label="任务状态">
        <el-tag type="primary" v-if="scheduleJob.status === 'true'">正常</el-tag>
        <el-tag type="danger" v-else>暂停</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="执行策略">
        <el-tag type="primary" v-if="scheduleJob.executeStrategy === 1">立即执行</el-tag>
        <el-tag type="success" v-else-if="scheduleJob.executeStrategy === 2">执行一次</el-tag>
        <el-tag type="danger" v-else-if="scheduleJob.executeStrategy === 3">放弃执行</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="是否并发">
        <el-tag type="primary" v-if="scheduleJob.concurrent">允许</el-tag>
        <el-tag type="danger" v-else>禁止</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="创建时间">{{ scheduleJob.createTime }}</el-descriptions-item>
      <el-descriptions-item label="更新时间">
        <span v-if="scheduleJob.updateTime">{{ scheduleJob.updateTime }}</span>
        <el-tag type="info" v-else>未更新</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="任务备注" :span="2">{{ scheduleJob.remark }}</el-descriptions-item>
      <el-descriptions-item label="创建者">{{ scheduleJob.createBy }}</el-descriptions-item>
      <el-descriptions-item label="更新者">
        <span v-if="scheduleJob.updateBy">{{ scheduleJob.updateBy }}</span>
        <el-tag type="info" v-else>未更新</el-tag>
      </el-descriptions-item>
    </el-descriptions>
  </el-drawer>
</template>

<script>
export default {
  name: 'ViewDrawer',

  data () {
    return {
      // 任务详细参数
      scheduleJob: {},
      // 是否打开对话框
      openView: false
    }
  },

  methods: {
    // 打开抽屉
    handleView (row) {
      this.openView = true
      this.scheduleJob = row
    },
    // 关闭抽屉
    onCloseView () {
      this.openView = false
    }
  }
}
</script>

<style lang="scss" scoped>
.descriptions-container {
  padding: 1.5rem;
}
.el-divider {
  margin: 1rem 0;
}
</style>
